Repository navigation
Accept list, tuple and non-default-index Series groups in group splits - #1665
Sohail Shaikh (sohailshk) wants to merge 5 commits into
Conversation
AutoML.fit(split_type='group') indexed the group labels positionally with groups[train_idx]. A list or tuple raised TypeError (holdout) or AttributeError (cv, no .iloc), and a pd.Series with a non-default index raised KeyError in the holdout split because it was indexed by label. Convert such group labels to an ndarray when the data is prepared.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the group-label positional-indexing fix.
No open issues 🎉
What changed in this PR
This PR fixes positional indexing of array-like group labels in FLAML’s group-based splits, extending earlier fixes for target and sample-weight alignment.
Changes:
- Normalize list, tuple, and pandas Series values for
groupsandgroups_valto NumPy arrays. - Add regression tests for holdout and cross-validation splits, custom
GroupKFold, and label alignment with permuted Series indexes.
| File | Description |
|---|---|
test/automl/test_split.py |
Adds coverage for supported group containers and positional label alignment. |
flaml/automl/task/generic_task.py |
Normalizes group labels during data validation for positional indexing. |
Review effort: Balanced
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
Overall review of the complete patch at 1c6d739579d67873b1fa29a82e0ec29fcc09e884: the six independent Medium review-code lenses completed using gemini-4-carbon at high reasoning, with unresolved test-evidence follow-ups retained.
Please cover caller-supplied X_val/y_val/non-array groups_val, and check the labels passed to each CV fold rather than only the rows seen by RandomForestClassifier.fit. Also assert that at least one captured fit actually holds out groups: set(counts) <= {0, 10} accepts full-data fits and does not establish that on its own.
The added regression tests give 8 passed, 1 skipped on each native Python 3.10 and 3.13 stack; identical definitions on exact main give 7 failed, 1 passed, 1 skipped. This verifies the stated list/tuple/Series fixes, not a complete Spark or optional-dependency matrix. I also checked the broader pd.Index concern: it fails identically on this head and main, and is outside the explicitly stated container fix, so I am not reporting it as a new regression or requiring unrelated broadening here.
The original six reviewer outcomes and this scope adjudication are retained in local artifact-only evidence commits. No clean overall signoff or PR approval is submitted while the focused test requests remain; no foreign thread was resolved or prior review dismissed.
Posted by thinkall-agent-auto-reviewer
Spy on the labels and rows handed to each evaluated fold, cover X_val/y_val with non-array groups and groups_val, and assert that at least one fit holds groups out.
|
Thanks for the review, thinkall. I've added the requested test coverage and pushed the changes in commit
This ensures that validation groups are handled correctly across different input types and index configurations.
Also added an explicit assertion that at least one captured fit actually holds out groups. This ensures the tests verify genuine group separation rather than passing without exercising the intended behavior.
These dependency-related failures are unrelated to this change. |
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
The selected group-split regressions produce 17 passes and one existing skip on each native stack, on both current and preceding production source. The new row-alignment and nonvacuity checks improve test evidence.
Remaining test-quality follow-ups: require captured training groups to be present before comparing them; for three-fold CV, verify three nonoverlapping validation sets covering the rows rather than accepting any one held-out fold; and exercise positional indexing directly on captured caller-supplied groups_val instead of normalizing it inside the assertion.
These are assertion gaps, not newly demonstrated production row misalignment. This Low test-delta review does not supersede the retained full Medium scope or grant whole-PR approval.
Posted by thinkall-agent-auto-reviewer
…k that CV validation folds partition the rows, index captured validation groups by position
|
Implemented all three requested changes:
The new CV test fails on |
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
Whole-PR review at 3708aab7453614f3b6a35925f9d70d960e4b27f4: the stronger group-presence checks help, but two verified issues remain.
- Group identity:
np.asarrayinflaml/automl/task/generic_task.py:265-268turns distinct integer1and string"1"labels into the same string. Actual caller-supplied holdout metrics preserve those identities on main but receive only string labels on both this head and its predecessor. This is a remaining whole-PR regression, not a new production change in the latest test-only commit. - Assertion cardinality: the new CV helper accepts a repeated validation row because it counts sets. Appending an extra captured validation-group label also passes the current supplied-validation test, whereas the predecessor rejects it. Count the raw validation IDs and assert exact label-vector lengths.
pd.Index CV and range holdout still fail on current, predecessor and main; those are inherited array-like limitations, not newly introduced regressions. Targeted current suites passed 48 tests with 2 skips across the two native stacks. This does not establish full supported-version or optional-dependency coverage.
The Low skill verdict remains issues found. Evidence is retained locally only; no review outputs are pushed to this PR.
Posted by thinkall-agent-auto-reviewer
Why are these changes needed?
groupsis documented as "None or array-like", butsplit_type="group"indexes the labels positionally. Realistic repro (iris,train_test_split(X, y, df["cluster"])which keeps the Series index, regression,split_type="group",eval_method="holdout"):KeyError: "None of [Index([9, 11, ...])] are in the [index]"on main; it runs on this branch (the cv variant already worked).Other cases on main (each run): a list or tuple raises
TypeError: only integer scalar arrays can be converted to a scalar index(holdout) orAttributeError: ... no attribute 'iloc'(cv, also withsplit_type=GroupKFold(3)). A Series whose index is a permutation of 0..n-1 raises nothing, but the holdout split stores other rows' labels instate.groups/state.groups_val(checked at state level; the effect on ranking metrics is from code reading only).The change converts list, tuple and Series group labels (and
groups_val) to an ndarray when the data is prepared. New tests: list, tuple, offset-index Series (holdout and cv), GroupKFold with a list (cv), and the permuted-index state check; 7 fail on main, all pass here. Existing test_split tests pass except two that import catboost (not installed).Related issue number
Related: #1384/#1385, #1396/#1405, #1586 (same indexing, sample_weight side).
Checks
Checks run: black (line length 120) and ruff on the changed files. The pinned pre-commit hook versions were not run. No doc changes are needed.